﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RobotTracking.CUiRTAttachFramesToObjectsForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.UpdateContinuousMfg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.RobotTracking;

internal class CUiRTAttachFramesToObjectsForm : TxForm
{
  private IContainer components;
  private Button m_buttonNo;
  private Button m_buttonYes;
  private Label m_noteLabel;
  private Label m_topMessageLabel;
  private PictureBox pictureBox1;
  private Label m_bottomMessageLabel;
  private RichTextBox m_detailsTextBox;

  internal CUiRTAttachFramesToObjectsForm()
  {
    this.InitializeComponent();
    this.SetTitles();
  }

  internal bool FillAttachmentPairs(List<CApRTRobotTrackingAttachmentPair> pairs)
  {
    try
    {
      this.m_detailsTextBox.Clear();
      string format = this.GetResourceManager().GetString("FORMAT_ATTACH_FRAMES_TO_OBJECTS_LISTING");
      foreach (CApRTRobotTrackingAttachmentPair pair in pairs)
      {
        if (pair != null)
          this.m_detailsTextBox.AppendText(string.Format(format, (object) ((ITxObject) pair.ObjectToAttach).Name, (object) ((ITxObject) pair.AttachmentParentCandidate).Name) + "\r\n");
      }
      return true;
    }
    catch (Exception ex)
    {
      return false;
    }
  }

  internal void AutoSizeControlsHeight()
  {
    ((Control) this).SuspendLayout();
    try
    {
      List<Control> controlList = new List<Control>();
      foreach (Control control in (ArrangedElementCollection) ((Control) this).Controls)
      {
        if (control != null && control.Top > this.m_noteLabel.Top && control != this.m_topMessageLabel && control != this.m_bottomMessageLabel && control != this.m_detailsTextBox)
          controlList.Add(control);
      }
      int height1 = this.m_topMessageLabel.Height;
      int height2 = this.m_bottomMessageLabel.Height;
      int height3 = this.m_noteLabel.Height;
      int num1 = this.MeasureAutoSizeHeight((Control) this.m_topMessageLabel);
      int num2 = this.MeasureAutoSizeHeight((Control) this.m_bottomMessageLabel);
      int num3 = this.MeasureAutoSizeHeight((Control) this.m_noteLabel);
      int num4 = 0;
      if (num1 > height1)
      {
        int num5 = num1 - height1;
        num4 += num5;
        this.m_topMessageLabel.Height = num1;
        this.m_detailsTextBox.Top += num5;
        this.m_bottomMessageLabel.Top += num5;
        this.m_noteLabel.Top += num5;
      }
      if (num2 > height2)
      {
        int num6 = num2 - height2;
        num4 += num6;
        this.m_noteLabel.Height = num3;
        this.m_noteLabel.Top += num6;
      }
      if (num3 > height3)
      {
        int num7 = num3 - height3;
        num4 += num7;
        this.m_noteLabel.Height = num3;
      }
      if (num4 != 0)
      {
        ((Control) this).Height = ((Control) this).Height + num4;
        foreach (Control control in controlList)
          control.Top += num4;
      }
      controlList.Clear();
    }
    catch (Exception ex)
    {
    }
    ((Control) this).ResumeLayout();
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.RobotTracking.Res.ResourceTable", ((object) this).GetType().Assembly);
  }

  private void SetTitles()
  {
    ((Control) this).Text = this.GetResourceManager().GetString("TITLE_ATTACH_FRAMES_TO_OBJECTS");
    this.m_topMessageLabel.Text = this.GetResourceManager().GetString("MSG_ATTACH_FRAMES_TO_OBJECTS_TOP_MESSAGE");
    this.m_bottomMessageLabel.Text = this.GetResourceManager().GetString("MSG_ATTACH_FRAMES_TO_OBJECTS_BOTTOM_MESSAGE");
    this.m_noteLabel.Text = this.GetResourceManager().GetString("MSG_ATTACH_FRAMES_TO_OBJECTS_NOTE_MESSAGE");
  }

  private int MeasureAutoSizeHeight(Control ctrl)
  {
    try
    {
      int width = ctrl.Width - ctrl.Margin.Horizontal - 2;
      Graphics graphics = ctrl.CreateGraphics();
      string[] separator = new string[1]{ "\r\n" };
      string[] strArray = ctrl.Text.Split(separator, StringSplitOptions.None);
      float num = 0.0f;
      foreach (string text in strArray)
      {
        if (text.Length < 1)
          text = "|";
        float height = graphics.MeasureString(text, ctrl.Font, width, StringFormat.GenericTypographic).Height;
        num += height;
      }
      graphics.Dispose();
      return (int) num + (ctrl.Margin.Vertical + 2);
    }
    catch
    {
      return 0;
    }
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiRTAttachFramesToObjectsForm));
    this.m_buttonNo = new Button();
    this.m_buttonYes = new Button();
    this.m_noteLabel = new Label();
    this.m_topMessageLabel = new Label();
    this.pictureBox1 = new PictureBox();
    this.m_bottomMessageLabel = new Label();
    this.m_detailsTextBox = new RichTextBox();
    ((ISupportInitialize) this.pictureBox1).BeginInit();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_buttonNo, "m_buttonNo");
    this.m_buttonNo.DialogResult = DialogResult.No;
    this.m_buttonNo.Name = "m_buttonNo";
    this.m_buttonNo.UseVisualStyleBackColor = true;
    componentResourceManager.ApplyResources((object) this.m_buttonYes, "m_buttonYes");
    this.m_buttonYes.DialogResult = DialogResult.Yes;
    this.m_buttonYes.Name = "m_buttonYes";
    this.m_buttonYes.UseVisualStyleBackColor = true;
    componentResourceManager.ApplyResources((object) this.m_noteLabel, "m_noteLabel");
    this.m_noteLabel.Name = "m_noteLabel";
    componentResourceManager.ApplyResources((object) this.m_topMessageLabel, "m_topMessageLabel");
    this.m_topMessageLabel.Name = "m_topMessageLabel";
    componentResourceManager.ApplyResources((object) this.pictureBox1, "pictureBox1");
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_bottomMessageLabel, "m_bottomMessageLabel");
    this.m_bottomMessageLabel.Name = "m_bottomMessageLabel";
    componentResourceManager.ApplyResources((object) this.m_detailsTextBox, "m_detailsTextBox");
    this.m_detailsTextBox.Name = "m_detailsTextBox";
    this.m_detailsTextBox.ReadOnly = true;
    this.m_detailsTextBox.Text = UCMStringTable.UMC_Verify;
    ((Form) this).AcceptButton = (IButtonControl) this.m_buttonYes;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonNo;
    ((Form) this).ControlBox = false;
    ((Control) this).Controls.Add((Control) this.m_detailsTextBox);
    ((Control) this).Controls.Add((Control) this.m_bottomMessageLabel);
    ((Control) this).Controls.Add((Control) this.m_buttonNo);
    ((Control) this).Controls.Add((Control) this.m_buttonYes);
    ((Control) this).Controls.Add((Control) this.m_noteLabel);
    ((Control) this).Controls.Add((Control) this.m_topMessageLabel);
    ((Control) this).Controls.Add((Control) this.pictureBox1);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedToolWindow;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiRTAttachFramesToObjectsForm);
    ((Form) this).ShowIcon = false;
    ((ISupportInitialize) this.pictureBox1).EndInit();
    ((Control) this).ResumeLayout(false);
  }
}
